package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ValidateException;
import com.cskaoyan.shopping.constants.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ProductCateConverter;
import com.cskaoyan.shopping.dal.entitys.ItemCat;
import com.cskaoyan.shopping.dal.persistence.ItemCatMapper;
import com.cskaoyan.shopping.dto.ProductCateDto;
import com.cskaoyan.shopping.service.IProductCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Aurhor: 徐云飞
 * @DATE: 2022/10/25 19:51
 * @Description:
 * @Version 1.0
 */
@Service
@Transactional
public class IProductCateServiceImpl implements IProductCateService {
    @Autowired
    ItemCatMapper itemCatMapper;
    @Autowired
    ProductCateConverter productCateConverter;

    @Override
    public List<ProductCateDto> getAllProductCate() {

        List<ProductCateDto> productCateDtos = null;
        try {
            List<ItemCat> itemCats =  itemCatMapper.selectAllByOrder();
            productCateDtos = productCateConverter.items2Dto(itemCats);
        } catch (Exception e) {
            throw new ValidateException(ShoppingRetCode.PRODUCT_NOT_EXISTS.getCode(),
                    ShoppingRetCode.PRODUCT_NOT_EXISTS.getMessage());
        }

        return productCateDtos;

    }
}
